/**
 * Created By zhangQ 2018/3/7
 */
import axiosUtils from '@api/env/axiosEnv'
import _ from 'lodash'

let customAxios = axiosUtils._initAxios()

export function getOrderLiquidation (param) {
  return customAxios({
    url: '/data/liquidation/orderLiquidation',
    method: 'post',
    data: param
  })
}

export function getTotalOrderLiquidation (param) {
  return customAxios({
    url: '/data/liquidation/orderLiquidation',
    method: 'post',
    data: {
      page: param.page,
      pageSize: param.pageSize
    }
  })
}

export function orderLiquidationByPage (param) {
  _.forIn(param, function (value, key) {
    if (!value) {
      delete param[key]
    }
  })
  // if (param.status && param.status.length > 0 && _.isArray(param.status)) {
  //   console.log(param)
  //   param.status = param.status.join(',')
  // }
  let paramClone = _.cloneDeep(param)
  if (paramClone.status && paramClone.status.length > 0 && _.isArray(param.status)) {
    paramClone.status = paramClone.status.join(',')
  }
  return customAxios({
    url: '/data/liquidation/orderLiquidationByPage',
    method: 'post',
    data: param
  })
}

export function orderLiquidationTotal (param) {
  _.forIn(param, function (value, key) {
    if (!value) {
      delete param[key]
    }
  })
  // if (param.status && param.status.length > 0 && _.isArray(param.status)) {
  //   param.status = param.status.join(',')
  // }
  let paramClone = _.cloneDeep(param)
  if (paramClone.status && paramClone.status.length > 0 && _.isArray(param.status)) {
    paramClone.status = paramClone.status.join(',')
  }
  return customAxios({
    url: '/data/liquidation/orderLiquidationTotal',
    method: 'post',
    data: param
  })
}

export function orderLiquidationData (param) {
  _.forIn(param, function (value, key) {
    if (!value) {
      delete param[key]
    }
  })
  let paramClone = _.cloneDeep(param)
  if (paramClone.status && paramClone.status.length > 0) {
    paramClone.status = paramClone.status.join(',')
  }
  return customAxios({
    url: '/data/liquidation/orderLiquidationData',
    method: 'post',
    data: paramClone
  })
}

// 车队报表 3.0
export function orderLiquidationDataForFleet (param) {
  return customAxios({
    url: 'main/fleetOrder/orderLiquidationDataForFleet',
    method: 'post',
    data: param
  })
}

// 车队报表 20180827
export function quertFleetReportFormByPage (param) {
  _.forIn(param, function (value, key) {
    if (!value) {
      delete param[key]
    }
  })
  console.log('state', param.state)
  if (param.state && param.state.length > 0) {
    param.state = param.state.join(',')
  }
  console.log('state', param.state)
  return customAxios({
    url: '/main/fleetOrderDetail/quertFleetReportFormByPage',
    method: 'post',
    data: param
  })
}
